package com.slkj.web.controller.shop;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.slkj.common.core.domain.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.slkj.common.annotation.Log;
import com.slkj.common.core.controller.BaseController;
import com.slkj.common.core.domain.AjaxResult;
import com.slkj.common.enums.BusinessType;
import com.slkj.common.utils.poi.ExcelUtil;
import com.slkj.common.core.page.TableDataInfo;
import com.slkj.shop.domain.ShopBanner;
import com.slkj.shop.service.IShopBannerService;

/**
 * 【请填写功能名称】Controller
 *
 * @author slkj
 * @date 2023-03-26
 */
@Api(tags = "轮播管理")
@RestController
@RequestMapping("/shop/banner")
public class ShopBannerController extends BaseController
{
    @Resource
    private IShopBannerService shopBannerService;

    /**
     * 查询【请填写功能名称】列表
     */
@ApiOperation("轮播图查询")
    @PreAuthorize("@ss.hasPermi('shop:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopBanner shopBanner)
    {
        startPage();
        List<ShopBanner> list = shopBannerService.selectShopBannerList(shopBanner);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @ApiOperation("轮播图导出")
    @PreAuthorize("@ss.hasPermi('shop:banner:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopBanner shopBanner)
    {
        List<ShopBanner> list = shopBannerService.selectShopBannerList(shopBanner);
        ExcelUtil<ShopBanner> util = new ExcelUtil<ShopBanner>(ShopBanner.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @ApiOperation("根据id轮播图查询")
    @PreAuthorize("@ss.hasPermi('shop:banner:query')")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return success(shopBannerService.selectShopBannerByBannerId(bannerId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("轮播图新增")
    @PreAuthorize("@ss.hasPermi('shop:banner:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopBanner shopBanner)
    {
        return toAjax(shopBannerService.insertShopBanner(shopBanner));
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation("轮播图编辑")
    @PreAuthorize("@ss.hasPermi('shop:banner:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopBanner shopBanner)
    {
        return toAjax(shopBannerService.updateShopBanner(shopBanner));
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation("轮播图删除")
    @PreAuthorize("@ss.hasPermi('shop:banner:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(shopBannerService.deleteShopBannerByBannerIds(bannerIds));
    }
    /**
     * 状态修改
     */
    @ApiOperation("轮播信息状态修改")
    @PreAuthorize("@ss.hasPermi('shop:banner:edit')")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody ShopBanner shopBanner) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("banner_id", shopBanner.getBannerId());
        updateWrapper.set("status", shopBanner.getStatus());
        boolean update = shopBannerService.update(updateWrapper);
        return toAjax(update);
    }
}
